package com.dingwen.stu.spr.auto.entity;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * 人
 *
 * @author dingwen
 * @date 2021/10/05
 */
@Component
@Scope("singleton")
public class People {
    /**
     * 名字
     */
    @Value("dingwen")
    private String name;
    /**
     * 猫
     *  @Autowired 先基于byType匹配，当同一类型Bean有多个时且byName不能完成匹配时，需要配合使用 @Qualifier指定Bean Id.
     */
    @Autowired(required = false)////如果显示的定义了Autowired的required属性为false，说明这个对象可以为null，否则不允许为空
    private Cat cat;
    /**
     * 狗
     *   @Resource 先基于byName匹配，当name与依赖对象set方法对应无法匹配时使用byType匹配，若都不能则需要通过name指定Bean Id.
     */
    @Resource()
    private Dog dog;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Cat getCat() {
        return cat;
    }

    public void setCat(Cat cat) {
        this.cat = cat;
    }

    public Dog getDog() {
        return dog;
    }

    public void setDog(Dog dog) {
        this.dog = dog;
    }

    @Override
    public String toString() {
        return "People{" +
                "name='" + name + '\'' +
                ", cat=" + cat +
                ", dog=" + dog +
                '}';
    }
}
